//
//  AlterNickNameViewController.m
//  HomeDelivery
//
//  Created by apple on 16/7/25.
//  Copyright © 2016年 apple. All rights reserved.
//

#import "AlterNickNameViewController.h"

@interface AlterNickNameViewController ()<UITextFieldDelegate>

@end

@implementation AlterNickNameViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor=LIGHTGRAY;
    self.title=@"修改昵称";
    self.sureAlterBtn.layer.cornerRadius=5;
    self.sureAlterBtn.clipsToBounds=YES;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
}
-(BOOL)textFieldShouldReturn:(UITextField *)textField
{
    [self.view endEditing:YES];
    return YES;
}
-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
{
    [self.view endEditing:YES];
}
- (IBAction)sureAlterNickName:(id)sender
{
    //http://192.168.1.107:35568/User/ModNickName
    //m_ModNickNamePara(AdminAccount,NewNickName,Timestamp,Sign)
    NSString *timeStamp=[GeneralTool gettimestamp];
    NSDictionary *dic=@{@"AdminAccount":ADMINACCOUNT,
                        @"NewNickName":self.nickNameTx.text,
                        @"Timestamp":timeStamp};
    NSString *sign=[GeneralTool GetSin:dic];
    NSDictionary *dataDic=@{@"AdminAccount":ADMINACCOUNT,
                            @"NewNickName":self.nickNameTx.text,
                            @"Timestamp":timeStamp,
                            @"Sign":sign};
    NSDictionary *requestDic=@{@"m_ModNickNamePara":dataDic};
    [RequestTool requestDataWithType:@"post" andUrlString:@"User/ModNickName" andParameters:requestDic andFinishedWith:^(id response, NSError *error) {
        if (error)
        {
            [MBProgressHUD showError:@"请求失败"];
        }else
        {
            if ([response[@"IsSuccess"]integerValue]==1)
            {
                [self.navigationController popToRootViewControllerAnimated:YES];
                [[NSNotificationCenter defaultCenter]postNotificationName:@"refreshTabBar" object:nil];
                [MBProgressHUD showSuccess:response[@"ReturnString"]];
            }else
            {
                [MBProgressHUD showError:response[@"ReturnString"]];

            }
        }
    }];
}
-(void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    self.navigationController.navigationBar.barTintColor=[UIColor whiteColor];
    self.navigationController.navigationBar.titleTextAttributes = @{NSForegroundColorAttributeName: [UIColor blackColor], NSFontAttributeName:[UIFont systemFontOfSize:18]};
    
}
@end
